layui.use('laydate', function(){
    var laydate = layui.laydate;
    
    var end = laydate.render({
    	elem: '#timeEnd', //指定元素
    	done:function(value,date){
    		start.config.max={
   				year:date.year,
   				month:date.month-1,
   				date:date.date
    		}
    	}
    })
    
    var start = laydate.render({
    	elem: '#timaStart', //指定元素
    	done:function(value,date){
    		end.config.min={
   				year:date.year,
   				month:date.month-1,
   				date:date.date
    		}
    	}
    })
    
  //执行一个laydate实例
    laydate.render({
      elem: '#timaStart' //指定元素
    });

    //执行一个laydate实例
    laydate.render({
      elem: '#timeEnd' //指定元素
    });
    
  });	 
layui.use('table', function(){
  var table = layui.table;
 
  //监听表格复选框选择
  table.on('checkbox(demo)', function(obj){
    console.log(obj)
  });
  //监听工具条
  table.on('tool(demo)', function(obj){
    var da = obj.data;
    //入库
    if(obj.event === 'quality'){
    	var index = layer.load(0, {
			  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
        layer.confirm('是否入库', function(index){
        	layer.close(index);
            var url="../../listenPurchase/addStock.action";
            var data={"qtId":da.qtId,"vocationalWorkId":da.vocationalWorkId};
            $.post(url,data,function(mes){
            	if(mes.datas==1){
            		layer.msg(mes.msg);
    				setTimeout(() => {
    					window.location.reload()
  						}, 500);
            	}
            },"json");
           
          });
     
    //质检
    } else if(obj.event === 'testing'){
    	layer.open({
    	  title:"质检",
  		  type: 2, //设置为iframe
  		  shift:1,//弹出框动画效果
  		  area: ['66%', '75%'],
  		  content: ['../purchaseMuQualityTesting/NowQualityTesting.html?purchaseId='+da.vocationalWorkId+"&qtId="+da.qtId, 'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
  		 
  	  }); 
    //查看质检详情
    }else if(obj.event === 'chaDetail'){
    	layer.open({
      	  title: "质检详情",
    		  type: 2, //设置为iframe
    		  shift:1,//弹出框动画效果
    		  area: ['66%', '45%'],
    		  content: ['../purchaseMuQualityTesting/purchaseQualityTestingDetail.html?qtId='+da.qtId, 'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    		 
    	  }); 
      }
  });
   
  //表单重载
  var $ = layui.$, active = {
		    reload: function(){
		    	var demoReload = $('#demoReload');
			    var purDateStart=$('#timaStart');
			    var purDateEnd=$('#timeEnd');
		      //执行重载
		      table.reload('idTest', {
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		        ,where: {
		        	startTime: purDateStart.val(),
		        	endTime: purDateEnd.val(),
		        	companyName:demoReload.val(),
		        }
		      });
		    }
		  };
  
  $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
 
  
  
});